//
//  MyHeadView.m
//  marrymarry
//
//  Created by lsj on 16/9/18.
//  Copyright © 2016年 cf. All rights reserved.
//

#import "MyHeadView.h"
@interface MyHeadView ()
{
     int midNum;
     int LieNum;
    int countNum;
}
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *headerContentViewTop;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *headInfoViewHeight;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *headerContentViewRight;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *headerContentViewLeft;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *headerContentHeight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *headerViewBottom;
@property (assign, nonatomic) CGFloat headerHeight;
@property (assign,nonatomic)CGFloat inforHeight;
@end
@implementation MyHeadView

- (void)awakeFromNib {
    self.headerHeight = 420;
    self.giftAndHeartView.layer.borderColor = RGB(216, 174, 102).CGColor;
    self.giftAndHeartView.layer.borderWidth = 1;
    self.giftAndHeartView.layer.cornerRadius = 8;
    self.headInfoView.layer.cornerRadius = 6;
    ///防止挡住前两条cell
//    self.autoresizesSubviews = NO;
    self.autoresizingMask = UIViewAutoresizingNone;
}
- (void)scrollDidScroll:(UIScrollView *)scrollView {
    CGFloat offset_Y = scrollView.contentOffset.y;
    if (offset_Y < 0) {
        self.headerContentViewTop.constant = offset_Y;
        self.headerContentViewLeft.constant = offset_Y / 2;
        self.headerContentViewRight.constant = offset_Y / 2;
       self.headerContentHeight.constant = self.headerHeight+(-offset_Y);
//        self.headerViewBottom.constant = 8;
    }
    [self layoutIfNeeded];
}

///根据userdefault来重新布局 并添加上盖有的标签label
- (void)reloadTheHeadInfoViewWithArry:(NSMutableArray *)dataArry
{
    
    countNum =0;
    int hangNum = 0;
    if (dataArry.count%4== 0) {
        hangNum =(int)dataArry.count/4;
          midNum = 4;
    }else
    {
        hangNum = (int)dataArry.count/4+1;
        midNum = dataArry.count%4;

    }
    NSLog(@"%d",hangNum);
    
    self.inforHeight = 125+hangNum*20;
    
    self.headInfoViewHeight.constant =self.inforHeight;
     [self layoutIfNeeded];
    
    ///加载新的标签时 先删除之前已有的label；
    for (UILabel * label  in self.headInfoView.subviews) {
        if ([label isKindOfClass:[UILabel class]]) {
            if (label.tag == 800) {
            }else
            {
                [label removeFromSuperview];
            }
        }
    }
    
    for (int j = 0; j<hangNum; j++) {
        if (j==hangNum-1) {
            LieNum=midNum;
        }else
        {
            LieNum =4;
        }
        for (int k = 0; k<LieNum; k++) {
            UILabel * myBiaoQianLabel = [UILabel new];
            myBiaoQianLabel.frame = CGRectMake(8*(k+1)+((self.frame.size.width-62)/4)*k,self.AddSignBtn.frame.origin.y+20+ 8*(j+1)+((125-40)/4)*j,(self.frame.size.width-62)/4, ((125-40)/4));
            myBiaoQianLabel.backgroundColor = [UIColor clearColor];
            myBiaoQianLabel.font = [UIFont systemFontOfSize:13];
            myBiaoQianLabel.layer.cornerRadius = 5;
            myBiaoQianLabel.layer.borderWidth =0.5;
            myBiaoQianLabel.layer.borderColor = [UIColor whiteColor].CGColor;
            myBiaoQianLabel.textAlignment = NSTextAlignmentCenter;
            myBiaoQianLabel.textColor = [UIColor whiteColor];
            
            myBiaoQianLabel.text = dataArry[countNum];
            countNum++;
            [self.headInfoView addSubview:myBiaoQianLabel];
        }
    }

    
    
    
    
    
    
}



@end
